home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ubufox / chrome / ubufox.jar / content / overlay.js < prev    next >
Encoding:
JavaScript  |  2009-04-14  |  5.6 KB  |  161 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  * 
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is distro-mods.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Canonical Ltd.
  18.  * Portions created by the Initial Developer are Copyright (C) 2007
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  * 
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. var ubufox = {
  38.   onAddonsLoad: function () {
  39.     this.isffox3 = false;
  40.     var labelGetUbuntu = document.getElementById("getUbuntu"); // ffox 2
  41.     var extensions = document.getElementById("extensions-view");
  42.     this.strings = document.getElementById("ubufox-strings");
  43.  
  44.     if (!labelGetUbuntu) {
  45.       labelGetUbuntu = document.getElementById("getUbuntu3");
  46.       this.isffox3 = true;
  47.     }
  48.     this.initialized = true;
  49.  
  50.     if (!ubufoxCheckExecutable("/usr/bin/gnome-app-install"))
  51.       labelGetUbuntu.setAttribute("hidden", "true");
  52.     else if (!this.isffox3) {
  53.       // this is ffox2 only because ffox3 uses a distinct overlay anchor
  54.       if (extensions.getAttribute("selected") != "true") {
  55.         labelGetUbuntu.setAttribute("hidden", "true");
  56.       }
  57.       if (extensions.getAttribute("selected") == "true") {
  58.         labelGetUbuntu.setAttribute("hidden", "false");
  59.       }
  60.       extensions.addEventListener("DOMAttrModified", function (e) { ubufox.onAttrModified(e); }, false);
  61.     }
  62.   },
  63.   onMenuItemCommand: function(e) {
  64.     var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  65.                                   .getService(Components.interfaces.nsIPromptService);
  66.     promptService.alert(window, this.strings.getString("helloMessageTitle"),
  67.                                 this.strings.getString("helloMessage"));
  68.   },
  69.   onAttrModified: function(e) {
  70.     var labelGetUbuntu = document.getElementById("getUbuntu");
  71.     var extensions = document.getElementById("extensions-view");
  72.  
  73.     if (!ubufoxCheckExecutable("/usr/bin/gnome-app-install")) {
  74.       labelGetUbuntu.setAttribute("hidden", "true");
  75.       return;
  76.     }
  77.     if (extensions.getAttribute("selected") != "true") {
  78.       labelGetUbuntu.setAttribute("hidden", "true");
  79.     }
  80.     if (extensions.getAttribute("selected") == "true") {
  81.       labelGetUbuntu.setAttribute("hidden", "false");
  82.     }
  83.   },
  84. };
  85. window.addEventListener("load", function(e) { ubufox.onAddonsLoad(e); }, false);
  86.  
  87. function startUbuntuAddonsWizard(ev)
  88. {
  89.   var executable =
  90.       Components.classes['@mozilla.org/file/local;1']
  91.       .createInstance(Components.interfaces.nsILocalFile);
  92.  
  93.   executable.initWithPath("/usr/bin/gnome-app-install");
  94.  
  95.   if(!executable.exists() || !executable.isExecutable())
  96.          alert('Unexpected error!');
  97.  
  98.   var procUtil =
  99.       Components.classes['@mozilla.org/process/util;1']
  100.       .createInstance(Components.interfaces.nsIProcess);
  101.  
  102.   var nsFile = executable.QueryInterface(Components.interfaces.nsIFile);
  103.  
  104.   procUtil.init(executable);
  105.  
  106.   var args = new Array("--xul-extensions=firefox");
  107.   // we care for firefox 2 and use a special mime type to document
  108.   // compatibility of extensions with it
  109.   if (!ubufox.isffox3) {
  110.     args = new Array("--xul-extensions=firefox-2");
  111.   }
  112.   var res = procUtil.run(false, args, args.length);
  113.  
  114.   return true;
  115. }
  116.  
  117. function ubufoxReportBug(event) {
  118.  
  119.   var executable =
  120.       Components.classes['@mozilla.org/file/local;1']
  121.       .createInstance(Components.interfaces.nsILocalFile);
  122.  
  123.   executable.initWithPath("/usr/bin/ubuntu-bug");
  124.  
  125.   if(!executable.exists () || !executable.isExecutable())
  126.          alert('Unexpected error!');
  127.  
  128.   var procUtil =
  129.       Components.classes['@mozilla.org/process/util;1']
  130.       .createInstance(Components.interfaces.nsIProcess);
  131.  
  132.   var nsFile = executable.QueryInterface(Components.interfaces.nsIFile);
  133.  
  134.   procUtil.init(executable);
  135.  
  136.   var args = new Array("-p", "firefox-3.0" );
  137.   var res = procUtil.run(false, args, args.length);
  138. }
  139.  
  140.  
  141. function ubufoxGetHelpOnline(event)
  142. {
  143.   openUILink("https://launchpad.net/distros/ubuntu/jaunty/+sources/firefox-3.0/+gethelp", event, false, true);
  144. }
  145.  
  146. function ubufoxHelpTranslateLaunchpad(event)
  147. {
  148.   openUILink("https://launchpad.net/distros/ubuntu/jaunty/+sources/firefox-3.0/+translate", event, false, true);
  149. }
  150.  
  151. function ubufoxCheckExecutable(filename)
  152. {
  153.   var executable =
  154.       Components.classes['@mozilla.org/file/local;1']
  155.       .createInstance(Components.interfaces.nsILocalFile);
  156.  
  157.   executable.initWithPath(filename);
  158.   return executable.exists();
  159. }
  160.  
  161.